<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<?php

$Username = $_SESSION['loginusername'];
$NRIC = $_REQUEST['barcode'];
$userCenterName = $_SESSION["centreName"];
$centreName = "";
include 'conn.php';
$qry = "Select CentreName from centre where CentreId = (SELECT client.CentreId from centre, client WHERE client.NRIC = '$NRIC' AND centre.CentreId = client.CentreId)";
$result1 = mysql_query($qry);
while ($row = mysql_fetch_array($result1)) {
    $centreName = $row['CentreName'];
}

include 'conn.php';
$result = mysql_query("Select * from attendancerecord where NRIC='" . $NRIC . "' AND DATE(SignInTimeStamp)=CURDATE()");
if ($centreName == $userCenterName) {
    if (mysql_num_rows($result) == 0) {
        mysql_query("INSERT INTO attendancerecord(  `NRIC` ,  `CentreId` ,  `SignInTimeStamp` ,  `Status` ,`AuditSignIn`) 
        VALUES (
        (

        SELECT  `NRIC` 
        FROM  `client` 
        WHERE  `NRIC` =  '$NRIC'
        ), (

        SELECT  `CentreId` 
        FROM  `client` 
        WHERE  `NRIC` =  '$NRIC'
        ), NOW( ) ,  'Not Verified','$Username'
        )");
    } else {
        echo "<font color='red'>Attendance has been taken!</font>";
    }
} else {
    echo "<font color='red'>This elderly is not from the " . $_SESSION['centreName'] . " Branch.</font>";
}
?>	